package com.letoken.platform.pub.enums;

import java.util.HashMap;
import java.util.Map;

/**
 * @version 1.0
 * @author： Christopher
 * @date： 2022/4/11 17:00
 */
public enum WebSocketMsgTypeEnum {

    MSGCOUNT("msgCount", "消息数量"),
    MSGACTIVITY("msgActivity", "消息列表"),

    WITHDRAW_NOFITY("WITHDRAW_NOFITY", "消息数量"),

    ;

    private String value;
    private String text;

    private static Map<String, WebSocketMsgTypeEnum> pool = new HashMap<>();

    static {
        for (WebSocketMsgTypeEnum each : WebSocketMsgTypeEnum.values()) {
            WebSocketMsgTypeEnum defined = pool.get(each.getValue());
            if (null != defined) {
                throw new IllegalArgumentException(defined.toString() + " defined as same code with "
                        + each.toString());
            }
            pool.put(each.getValue(), each);
        }
    }

    WebSocketMsgTypeEnum(String value, String text) {
        this.value = value;
        this.text = text;
    }


    public static WebSocketMsgTypeEnum valueOf(int value) {
        return pool.get(String.valueOf(value));
    }

    public String getValue() {
        return this.value;
    }

    public String getText() {
        return text;
    }

    public static boolean isSupport(String val) {
        for (WebSocketMsgTypeEnum openState : values()) {
            if (openState.getValue().equals(val)) {
                return true;
            }
        }
        return false;
    }

    public static String getText(String val) {
        for (WebSocketMsgTypeEnum openState : values()) {
            if (openState.getValue().equals(val)) {
                return openState.getText();
            }
        }
        return "";
    }
}
